<!--
 * @Author: LBH 1336709799@qq.com
 * @Date: 2024-11-12 22:04:15
 * @LastEditors: LBH 1336709799@qq.com
 * @LastEditTime: 2024-11-13 19:56:18
 * @FilePath: \Day03\医疗诊断系统\hospital\src\App.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <h1>医疗诊断系统</h1>
    <form >
      <div>
        <label for="name">姓名:</label>
        <input type="text" v-model="patient.name" id="name" >
      </div>
      <div>
        <label for="age">年龄:</label>
        <input type="number" v-model="patient.age" id="age" >
      </div>
      <div>
        <label for="height">身高</label>
        <input type="number" v-model="patient.height" id="height"  >（米）
      </div>
      <div>
        <label for="weight">体重</label>
        <input type="number" v-model="patient.weight" id="weight" >（公斤）
      </div>

      <div>
        <label for="medicalHistory">病史</label>
        <input type="text" v-model="patient.medicalHistory" id="medicalHistory" >
      </div>
      <button type="button" @click="diagnose">诊断</button>
    </form>
    <div v-if="result">
      <h2>诊断结果:患者{{ patient.name }}的诊断结果为: {{ result }}</h2>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      patient: {
        name: '',
        age: '',
        height: '',
        weight: '',
        medicalHistory: ''
      },
      result: ''
    }
  },
  methods: {
    diagnose() {
      const height = this.patient.height;
      const weight = this.patient.weight;
      if (height > 0) {
        const bmi = weight / (height * height);
        if (bmi <= 18.5) {
          this.result = '体重过轻';
        } else if (bmi <= 24.9) {
          this.result = '正常';
        } else if (bmi <= 29.9) {
          this.result = '体重过重';
        } else {
          this.result = '肥胖';
        }
      } else {
        this.result = '身高必须大于零';
      }
    }
  }
}
</script>

<style scoped>
div {
  margin-bottom: 25px;
}
</style>